package com.xia.netty.thread.aqs;

import java.util.concurrent.locks.ReentrantLock;

public class AQSDemo {
    public static int i = 0;
    static ReentrantLock reentrantLock = new ReentrantLock(true);

    public static void main(String[] args) {

        try {
            Thread t1 = new Thread(() -> add());
            Thread t2 = new Thread(() -> add());
            Thread t3 = new Thread(() -> add());
            t1.start();
            t2.start();
            t3.start();
//            t1.join();
//            t2.join();
//            t3.join();
            Thread.sleep(3000);

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(i);

    }

    public static void add() {
        reentrantLock.lock();
        try {
            for (int j = 0; j < 1000; j++) {
                i++;
            }
        } catch (Exception e) {
        } finally {
            reentrantLock.unlock();
        }
    }


}
